/*
@title: Wordescaper
@description: "Wordescaper" is a word-guessing game where players aim to discover all possible words that can be formed using a set of seven letters. With up to 9 levels, each level challenges players to find 8 distinct words by selecting and confirming letters. The game avoids plural and similar words to create unique and engaging puzzles.
@author: Frank Z
@tags: ['utility']
@addedOn: 2024-09-16
*/

/*
To select a button, select the tile the cursor is already on to confirm input,
  basically requires double clicking the tile
S for the check/input-word button, can be used to clear if you make a typo

Hint: In general I avoid duplicates via plurality(not the same word plural and singular), 
    and similar words(cat and bat, etc.)
  For solutions scroll to the word sets at the bottom

If you want to make custom levels, just copy an entire if statement for a level(at the bottom),
  set the level number, the 8 words(max 7 letters, no repeat characters(I think)),
    the 7 letters and their values, and
  duplicate a map into the map list(before the win screen), 
    set level number and add Xs for word lengths
*/

const cursor = "c"
const BG1 = "a"
const BG2 = "s"
const BG3 = "d"
const BG4 = "f"
const BG5 = "g"
const LTitle = "l"
const VTitle = "v"
const Check = "z"
const Check2 = "n"
const X = "x"
const X2 = "b"
const LetterSprite1 = "1"
const LetterSprite2 = "2"
const LetterSprite3 = "3"
const LetterSprite4 = "4"
const LetterSprite5 = "5"
const LetterSprite6 = "6"
const LetterSprite7 = "7"
const Number0 = "q"
const Number1 = "w"
const Number2 = "e"
const Number3 = "r"
const Number4 = "t"
const Number5 = "y"
const Number6 = "u"
const Number7 = "i"
const Number8 = "o"
const Number9 = "p"

// storing letter sprites to be referenced
const LetterA = bitmap`
10............01
0.....00000....0
.....0000000....
.....00...00....
.....00...00....
....00.....00...
....00.....00...
....00.....00...
....000000000...
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
0...00.....00..0
10............01`
const LetterB = bitmap`
10............01
0...0000000....0
....00000000....
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00000000....
....00000000....
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00000000....
0...0000000....0
10............01`
const LetterC = bitmap`
10............01
0.....000000...0
.....00000000...
....000....00...
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....000....00...
.....00000000...
0.....000000...0
10............01`
const LetterD = bitmap`
10............01
0...0000000....0
....00000000....
....00....000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00....000...
....00000000....
0...0000000....0
10............01`
const LetterE = bitmap`
10............01
0....00000000..0
....000000000...
....00..........
....00..........
....00..........
....00..........
....000000......
....000000......
....00..........
....00..........
....00..........
....00..........
....000000000...
0....00000000..0
10............01`
const LetterF = bitmap`
10............01
0....00000000..0
....000000000...
....00..........
....00..........
....00..........
....00..........
....0000000.....
....0000000.....
....00..........
....00..........
....00..........
....00..........
....00..........
0...00.........0
10............01`
const LetterG = bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00..........
....00..........
....00..........
....00..0000....
....00..00000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`
const LetterH = bitmap`
10............01
0...00.....00..0
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
0...00.....00..0
10............01`
const LetterI = bitmap`
10............01
0...00000000...0
....00000000....
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
....00000000....
0...00000000...0
10............01`
const LetterJ = bitmap`
10............01
0....00000000..0
.....00000000...
........00......
........00......
........00......
........00......
........00......
........00......
........00......
........00......
...00...00......
...000..00......
....000000......
0....0000......0
10............01`
const LetterK = bitmap`
10............01
0...00.....00..0
....00....000...
....00....00....
....00...00.....
....00..000.....
....00..00......
....00.00.......
....00000.......
....000000......
....00..000.....
....00...00.....
....00....00....
....00....000...
0...00.....00..0
10............01`
const LetterL = bitmap`
10............01
0...00.........0
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....00..........
....000000000...
0...000000000..0
10............01`
const LetterM = bitmap`
10............01
0..00......00..0
...000....000...
...000....000...
...0000..0000...
...0000000000...
...00.0000.00...
...00..00..00...
...00......00...
...00......00...
...00......00...
...00......00...
...00......00...
...00......00...
0..00......00..0
10............01`
const LetterN = bitmap`
10............01
0...00.....00..0
....000....00...
....000....00...
....0000...00...
....0000...00...
....00.00..00...
....00.00..00...
....00..00.00...
....00..00.00...
....00...0000...
....00...0000...
....00....000...
....00....000...
0...00.....00..0
10............01`
const LetterO = bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`
const LetterP = bitmap`
10............01
0....000000....0
....00000000....
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00000000....
....0000000.....
....00..........
....00..........
....00..........
....00..........
....00..........
0...00.........0
10............01`
const LetterQ = bitmap`
10............01
0...0000000....0
...000000000....
...00.....00....
...00.....00....
...00.....00....
...00.....00....
...00.....00....
...00...0.00....
...00...0000....
...00....000....
...00.....00....
...00.....000...
...00000000000..
0...0000000..0.0
10............01`
const LetterR = bitmap`
10............01
0....000000....0
....00000000....
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00000000....
....0000000.....
....00...00.....
....00....00....
....00....00....
....00.....00...
0...00.....00..0
10............01`
const LetterS = bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00..........
....00..........
....00..........
....00000000....
.....00000000...
...........00...
...........00...
...........00...
....00.....00...
....000000000...
0....0000000...0
10............01`
const LetterT = bitmap`
10............01
0..0000000000..0
...0000000000...
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
0......00......0
10............01`
const LetterU = bitmap`
10............01
0...00.....00..0
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`
const LetterV = bitmap`
10............01
0..0........0..0
...00......00...
...00......00...
...00......00...
....00....00....
....00....00....
....00....00....
.....00..00.....
.....00..00.....
.....00..00.....
......0000......
......0000......
.......00.......
0......00......0
10............01`
const LetterW = bitmap`
10............01
00............00
.00..........00.
.00..........00.
.00..........00.
.00..........00.
.00..........00.
.00....00....00.
.00...0000...00.
..00.00..00.00..
..00.00..00.00..
..00.00..00.00..
..00.00..00.00..
...000....000...
0...0......0...0
10............01`
const LetterX = bitmap`
10............01
0...00.....00..0
....00.....00...
.....00...00....
.....00...00....
......00.00.....
......00.00.....
.......000......
.......000......
......00.00.....
......00.00.....
.....00...00....
.....00...00....
....00.....00...
0...00.....00..0
10............01`
const LetterY = bitmap`
10............01
0..0........0..0
...00......00...
...00......00...
....00....00....
....00....00....
.....00..00.....
.....00..00.....
......0000......
......0000......
.......00.......
.......00.......
.......00.......
.......00.......
0......00......0
10............01`
const LetterZ = bitmap`
10............01
0...000000000..0
....000000000...
..........000...
.........000....
.........00.....
........00......
........00......
.......00.......
.......00.......
......00........
.....000........
....000.........
....000000000...
0...000000000..0
10............01`

// creating 7 letter variables for displaying
let Letter1 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter2 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter3 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter4 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter5 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter6 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;
let Letter7 = bitmap`
10LLLLLLLLLLLL01
1..............1
................
................
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
................
................
1..............1
1011111111111101`;

// creating 7 letter values to match variables ^^
let LetterValue1 = "";
let LetterValue2 = "";
let LetterValue3 = "";
let LetterValue4 = "";
let LetterValue5 = "";
let LetterValue6 = "";
let LetterValue7 = "";

// create word set array
let wordset = [
  "",
  "",
  "",
  "",
  "",
  "",
  "",
  ""
];

// creating back-end variables at needed starting values
let inputword = "";
let letterstyped = 0;
let typelocation = 8;
let correctwords = 0

// create sprite names for 7 letters in array to be referenced with index
let lettersprites = [
  LetterSprite1,
  LetterSprite2,
  LetterSprite3,
  LetterSprite4,
  LetterSprite5,
  LetterSprite6,
  LetterSprite7
]

// create tunes
TuneWrong = tune`
200,
200: A5-200 + G4^200 + F4~200 + E4/200,
200: F4^200 + E4~200 + D4/200 + F5-200,
200: C4/200 + D4~200 + E4^200 + D5-200,
5600`
TuneRight = tune`
166.66666666666666,
166.66666666666666: D5-166.66666666666666 + C4/166.66666666666666 + D4~166.66666666666666 + E4^166.66666666666666,
166.66666666666666: F5-166.66666666666666 + E4~166.66666666666666 + D4/166.66666666666666 + G4^166.66666666666666,
166.66666666666666: B4^166.66666666666666 + A5-166.66666666666666 + G4~166.66666666666666 + E4/166.66666666666666,
4666.666666666666`
TuneNextLevel = tune`
125,
125: F4^125 + E4~125 + C4/125,
125: C4/125 + E4~125 + F4^125,
125: D4/125 + G4^125 + F4~125,
125: D4/125 + F4~125 + G4^125,
125: E4/125 + G4~125 + A4^125,
125: F4/125 + A4~125 + B4^125,
125: G4/125 + B4~125 + C5^125,
125: A4/125 + C5~125 + D5^125,
125: B4/125 + D5~125 + E5^125,
125: C5/125 + E5~125 + F5^125,
2625`

// create letter values for 7 letters in array to be referenced and able to be refreshed with the function
function updatelettervalues() {
  lettervalues = [
    LetterValue1,
    LetterValue2,
    LetterValue3,
    LetterValue4,
    LetterValue5,
    LetterValue6,
    LetterValue7
  ]
};

// setLegend for sprites in a function to be refreshed
function updatelegend() {
  setLegend(
    [cursor, bitmap`
..3.33.33.33.3..
................
3..............3
................
3..............3
3..............3
................
3..............3
3..............3
................
3..............3
3..............3
................
3..............3
................
..3.33.33.33.3..`],
    [BG1, bitmap`
10LLLL1LL1111101
01L111L111111110
L11L11111111111L
LLL111111111112L
L111111111111111
1L1111111111112L
111111111111111L
L11111111111112L
111111111111111L
111111111111112L
1111111111111221
111111111111112L
L11111111111211L
L111111112111221
0111221211212210
101LL11LLLL1LL01`],
    [BG2, bitmap`
10............01
0..............0
................
................
................
................
................
................
................
................
................
................
................
................
0..............0
10............01`],
    [BG3, bitmap`
10LLLLLLLLLLLL01
0..............0
................
................
................
................
................
................
................
................
................
................
................
................
0..............0
1011111111111101`],
    [BG4, bitmap`
10LLLLLLLLLLLL01
0..............0
................
................
................
................
................
................
................
................
................
................
................
................
0..............0
1077777777777701`],
    [BG5, bitmap`
10LLLLLLLLLLLL01
1..............1
................
...0........0...
....0......0....
.....0....0.....
......0..0......
.......00.......
.......00.......
......0..0......
.....0....0.....
....0......0....
...0........0...
................
1..............1
1011111111111101`],
    [LTitle, bitmap`
1022222222222201
0222002222222220
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222002222222222
2222000000002222
0222000000002220
1022222222222201`],
    [VTitle, bitmap`
1022222222222201
0220222222220220
2220022222200222
2220022222200222
2220022222200222
2222002222002222
2222002222002222
2222002222002222
2222200220022222
2222200220022222
2222200220022222
2222220000222222
2222220000222222
2222222002222222
0222222002222220
1022222222222201`],
    [Check, bitmap`
1044444444444401
0..............0
4...........D..4
4..........D4D.4
4.........D444D4
4........D444D.4
4.......D444D..4
4..D...D444D...4
4.D4D.D444D....4
4D444D444D.....4
4.D44444D......4
4..D444D.......4
4...D4D........4
4....D.........4
0..............0
1044444444444401`],
    [Check2, bitmap`
10LLLL1LL1111101
01L111L111111110
L11L11111111111L
LLL111111111412L
L111111111144111
1L1111111144112L
111111111441111L
L11111114411112L
114411144111111L
111441441111112L
1111444111111221
111114111111112L
L11111111111211L
L111111112111221
0111221211212210
101LL11LLLL1LL01`],
    [X, bitmap`
1033333333333301
0..............0
3..............3
3...3......3...3
3..333....333..3
3...333..333...3
3....333333....3
3.....3333.....3
3.....3333.....3
3....333333....3
3...333..333...3
3..333....333..3
3...3......3...3
3..............3
0..............0
1033333333333301`],
    [X2, bitmap`
10LLLL1LL1111101
01L111L111111110
L11L11111111111L
LLL311111111312L
L111311111131111
1L1113111131112L
111111311311111L
L11111133111112L
111111133111111L
111111311311112L
1111131111311221
111131111113112L
L11311111111311L
L111111112111221
0111221211212210
101LL11LLLL1LL01`],
    [Number0, bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00...0.00...
....00..00.00...
....00.00..00...
....00.0...00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [Number1, bitmap`
10............01
0.....000......0
.....0000.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.......00.......
.....000000.....
0....000000....0
10............01`],
    [Number2, bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
...........00...
...........00...
..........000...
.........000....
........000.....
.......000......
......000.......
.....000........
....000.........
....000000000...
0...000000000..0
10............01`],
    [Number3, bitmap`
10............01
0...000000000..0
....000000000...
..........000...
.........000....
........000.....
.......000......
......000000....
......0000000...
...........00...
...........00...
...........00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [Number4, bitmap`
10............01
0........000...0
........0000....
.......00000....
.......00.00....
......00..00....
......00..00....
.....00...00....
.....00...00....
....00....00....
....0000000000..
....0000000000..
..........00....
..........00....
0.........00...0
10............01`],
    [Number5, bitmap`
10............01
0...000000000..0
....000000000...
....00..........
....00..........
....00..........
....00..........
....00000000....
.....00000000...
...........00...
...........00...
...........00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [Number6, bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00..........
....00..........
....00..........
....00000000....
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [Number7, bitmap`
10............01
0...000000000..0
....000000000...
...........00...
..........00....
..........00....
.........00.....
.........00.....
........00......
........00......
.......00.......
.......00.......
......00........
......00........
0.....00.......0
10............01`],
    [Number8, bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
.....0000000....
.....0000000....
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [Number9, bitmap`
10............01
0....0000000...0
....000000000...
....00.....00...
....00.....00...
....00.....00...
....00.....00...
....000000000...
.....00000000...
...........00...
...........00...
...........00...
....00.....00...
....000000000...
0....0000000...0
10............01`],
    [LetterSprite1, Letter1],
    [LetterSprite2, Letter2],
    [LetterSprite3, Letter3],
    [LetterSprite4, Letter4],
    [LetterSprite5, Letter5],
    [LetterSprite6, Letter6],
    [LetterSprite7, Letter7]
  )
};
updatelegend();

// clears and adds the 7 letters in input tiles
function set7letters() {
  clearTile(3, 3);
  clearTile(4, 4);
  clearTile(5, 5);
  clearTile(4, 6);
  clearTile(2, 6);
  clearTile(1, 5);
  clearTile(2, 4);
  addSprite(3, 3, LetterSprite1);
  addSprite(4, 4, LetterSprite2);
  addSprite(5, 5, LetterSprite3);
  addSprite(4, 6, LetterSprite4);
  addSprite(2, 6, LetterSprite5);
  addSprite(1, 5, LetterSprite6);
  addSprite(2, 4, LetterSprite7);
};

// checks if the cursor is at the desired position
function checkforcursor(x, y) {
  let sprites = getTile(x, y);
  for (let sprite of sprites) {
    if (sprite.type === cursor) {
      return true;
    }
  }
};

// clears the 8 entry tiles at the top and the input word
function clearentry() {
  for (let tile = 8; tile <= 14; tile++) {
    clearTile(tile, 0)
    addSprite(tile, 0, BG4)
  }
    letterstyped = 0;
    inputword = "";
};

function placecursor() {
  addSprite(3, 3, cursor);
}

// prints the typed letter at the top and adds the value to the input word
function submitletter(inputtile) {
  if (letterstyped === 7) { // resets input if the input word is full
    clearentry();
  }
  typelocation = 8 + letterstyped;
  addSprite(typelocation, 0, lettersprites[inputtile]);
  inputword += lettervalues[inputtile];
  letterstyped += 1;
};

function submitword() {
  if (wordset.indexOf(inputword) !== -1) { // if the input word is in the word set
    playTune(TuneRight); 
    clearTile(7, 0) // flashes check mark next to input tiles
    addSprite(7, 0, Check2)
    setTimeout(() => {
      clearTile(7, 0)
      addSprite(7, 0, BG1)
    }, 800);
    clearTile(7, wordset.indexOf(inputword) + 1); // adds check next to word correctly guessed
    addSprite(7, wordset.indexOf(inputword) + 1, Check);
    correctwords += 1;
    for (let letter = 0; letter < inputword.length; letter++) { // for every letter in the input word
      for (let lettervalue = 0; lettervalue <= 6; lettervalue++) { // for all the 7 letters
        if ((inputword[letter]) === lettervalues[lettervalue]) { // check if they match
          addSprite(letter + 8, wordset.indexOf(inputword) + 1, lettersprites[lettervalue]); // print the sprite for the letter 
        }
      }
    }
    wordset[wordset.indexOf(inputword)] = "1"; // replaces word in word set with 1 to remove ability to get it correct multiple times
  }
  else {
    playTune(TuneWrong);
    clearTile(7, 0) // flashes x next to input tiles
    addSprite(7, 0, X2)
    setTimeout(() => {
      clearTile(7, 0)
      addSprite(7, 0, BG1)
    }, 800);
  }
  setTimeout(() => { // if all words are correct then pause and go to next level
    if (correctwords === 8) {
      playTune(TuneNextLevel);
      correctwords = 0;
      level += 1;
      setMap(levels[level]);
      checkandloadlevel();
    }
  }, 1500);
  clearentry();
  
};

// inputs
onInput("w", () => {
  if (checkforcursor(3, 3)) { // if the cursor is on that tile already, then input the letter associated
    submitletter(0);
  }
  getFirst(cursor).remove(); // "moves" the cursor to the tile
  addSprite(3, 3, cursor);
});
onInput("l", () => {
  if (checkforcursor(4, 4) === true) {
    submitletter(1);
  }
  getFirst(cursor).remove();
  addSprite(4, 4, cursor);
});
onInput("d", () => {
  if (checkforcursor(5, 5) === true) {
    submitletter(2);
  }
  if (cursor) {
    getFirst(cursor).remove();
  }
  addSprite(5, 5, cursor);
});
onInput("k", () => {
  if (checkforcursor(4, 6) === true) {
    submitletter(3);
  }
  getFirst(cursor).remove();
  addSprite(4, 6, cursor);
});
onInput("s", () => {
  if (checkforcursor(3, 7) === true) {
    submitword();
  }
  getFirst(cursor).remove();
  addSprite(3, 7, cursor);
});
onInput("j", () => {
  if (checkforcursor(2, 6) === true) {
    submitletter(4);
  }
  getFirst(cursor).remove();
  addSprite(2, 6, cursor);
});
onInput("a", () => {
  if (checkforcursor(1, 5) === true) {
    submitletter(5);
  }
  getFirst(cursor).remove();
  addSprite(1, 5, cursor);
});
onInput("i", () => {
  if (checkforcursor(2, 4) === true) {
    submitletter(6);
  }
  getFirst(cursor).remove();
  addSprite(2, 4, cursor);
});

// define maps, only differences are the level # and Xs for word lengths
let level = 0
const levels = [
  map`
aaaaaaaafffffff
alvlsqaxddddggg
aaaaaaaxddddggg
aaa1aaaxddddggg
aa7a2aaxddddggg
a6aaa3axddddggg
aa5a4aaxdddgggg
aaazaaaxdddgggg
aaaaaaaxdddgggg`,
  map`
aaaaaaaafffffff
alvlswaxddddddd
aaaaaaaxddddddg
aaa.aaaxddddddg
aa.a.aaxdddddgg
a.aaa.axdddddgg
aa.a.aaxddddggg
aaazaaaxddddggg
aaaaaaaxdddgggg`,
  map`
aaaaaaaafffffff
alvlseaxddddddd
aaaaaaaxddddddg
aaa.aaaxddddddg
aa.a.aaxdddddgg
a.aaa.axdddddgg
aa.a.aaxdddddgg
aaazaaaxddddggg
aaaaaaaxddddggg`,
  map`
aaaaaaaafffffff
alvlsraxddddddd
aaaaaaaxddddddd
aaa.aaaxddddddg
aa.a.aaxddddddg
a.aaa.axdddddgg
aa.a.aaxdddddgg
aaazaaaxddddggg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
alvlstaxddddddd
aaaaaaaxddddddg
aaa.aaaxdddddgg
aa.a.aaxdddddgg
a.aaa.axddddggg
aa.a.aaxddddggg
aaazaaaxddddggg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
alvlsyaxddddddd
aaaaaaaxddddddg
aaa.aaaxdddddgg
aa.a.aaxdddddgg
a.aaa.axdddddgg
aa.a.aaxddddggg
aaazaaaxddddggg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
alvlsuaxddddddd
aaaaaaaxddddddd
aaa.aaaxddddddg
aa.a.aaxddddddg
a.aaa.axddddddg
aa.a.aaxdddddgg
aaazaaaxdddddgg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
alvlsiaxddddddd
aaaaaaaxddddddg
aaa.aaaxdddddgg
aa.a.aaxdddddgg
a.aaa.axdddddgg
aa.a.aaxddddggg
aaazaaaxddddggg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
alvlsoaxddddddd
aaaaaaaxddddddg
aaa.aaaxdddddgg
aa.a.aaxdddddgg
a.aaa.axddddggg
aa.a.aaxddddggg
aaazaaaxddddggg
aaaaaaaxdddgggg`, 
  map`
aaaaaaaafffffff
alvlspaxddddddd
aaaaaaaxddddddd
aaa.aaaxddddddg
aa.a.aaxddddddg
a.aaa.axdddddgg
aa.a.aaxdddddgg
aaazaaaxddddggg
aaaaaaaxddddggg`, 
  map`
aaaaaaaafffffff
azzzzzazddddddd
aaaaaaazddddddd
aaazaaazddddddd
aazazaazddddddd
azaaazazddddddd
aazazaazddddddd
aaazaaazddddddd
aaaaaaazddddddd`
]
setMap(levels[level]);

// runs to make sure the level change is registered
function checkandloadlevel() {
  if (level === levels.length - 1) { // last level win screen
    Letter1 = LetterY;
    Letter2 = LetterO;
    Letter3 = LetterU;
    Letter4 = LetterW;
    Letter5 = LetterI;
    Letter6 = LetterN;
    updatelettervalues();
    updatelegend();
    for (let winscreenX = 1; winscreenX <= 8; winscreenX += 2) { // print "you win" a bunch
      addSprite(8, winscreenX, LetterSprite1);
      addSprite(9, winscreenX, LetterSprite2);
      addSprite(10, winscreenX, LetterSprite3);
      addSprite(12, winscreenX, LetterSprite4);
      addSprite(13, winscreenX, LetterSprite5);
      addSprite(14, winscreenX, LetterSprite6);
    }
  };
  
  if (level === 0) {
    wordset = [
      "dawk",
      "dial",
      "walk",
      "wild",
      "jail",
      "jaw",
      "kid",
      "aid"
    ]
    Letter1 = LetterW; // sets 7 letters for input and their values in clockwise order
    Letter2 = LetterL;
    Letter3 = LetterD;
    Letter4 = LetterK;
    Letter5 = LetterJ;
    Letter6 = LetterA;
    Letter7 = LetterI;
    LetterValue1 = "w";
    LetterValue2 = "l";
    LetterValue3 = "d";
    LetterValue4 = "k";
    LetterValue5 = "j";
    LetterValue6 = "a";
    LetterValue7 = "i";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 1) {
    wordset = [
      "adviser",
      "divers",
      "varied",
      "aside",
      "reads",
      "save",
      "idea",
      "air"
    ]
    Letter1 = LetterD;
    Letter2 = LetterS;
    Letter3 = LetterA;
    Letter4 = LetterR;
    Letter5 = LetterV;
    Letter6 = LetterE;
    Letter7 = LetterI;
    LetterValue1 = "d";
    LetterValue2 = "s";
    LetterValue3 = "a";
    LetterValue4 = "r";
    LetterValue5 = "v";
    LetterValue6 = "e";
    LetterValue7 = "i";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 2) {
    wordset = [
      "chemist",
      "ethics",
      "itches",
      "smith",
      "chime",
      "heist",
      "mice",
      "time"
    ]
    Letter1 = LetterM;
    Letter2 = LetterT;
    Letter3 = LetterE;
    Letter4 = LetterH;
    Letter5 = LetterS;
    Letter6 = LetterI;
    Letter7 = LetterC;
    LetterValue1 = "m";
    LetterValue2 = "t";
    LetterValue3 = "e";
    LetterValue4 = "h";
    LetterValue5 = "s";
    LetterValue6 = "i";
    LetterValue7 = "c";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 3) {
    wordset = [
      "ignores",
      "regions",
      "senior",
      "singer",
      "resin",
      "noise",
      "gone",
      "rose"
    ]
    Letter1 = LetterI;
    Letter2 = LetterG;
    Letter3 = LetterR;
    Letter4 = LetterS;
    Letter5 = LetterN;
    Letter6 = LetterE;
    Letter7 = LetterO;
    LetterValue1 = "i";
    LetterValue2 = "g";
    LetterValue3 = "r";
    LetterValue4 = "s";
    LetterValue5 = "n";
    LetterValue6 = "e";
    LetterValue7 = "o";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 4) {
    wordset = [
      "pyramid",
      "myriad",
      "diary",
      "rapid",
      "arid",
      "ramp",
      "pair",
      "army"
    ]
    Letter1 = LetterD;
    Letter2 = LetterP;
    Letter3 = LetterI;
    Letter4 = LetterY;
    Letter5 = LetterM;
    Letter6 = LetterR;
    Letter7 = LetterA;
    LetterValue1 = "d";
    LetterValue2 = "p";
    LetterValue3 = "i";
    LetterValue4 = "y";
    LetterValue5 = "m";
    LetterValue6 = "r";
    LetterValue7 = "a";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 5) {
    wordset = [
      "vacuole",
      "alcove",
      "clove",
      "value",
      "vocal",
      "clue",
      "love",
      "oval"
    ]
    Letter1 = LetterC;
    Letter2 = LetterA;
    Letter3 = LetterO;
    Letter4 = LetterV;
    Letter5 = LetterU;
    Letter6 = LetterE;
    Letter7 = LetterL;
    LetterValue1 = "c";
    LetterValue2 = "a";
    LetterValue3 = "o";
    LetterValue4 = "v";
    LetterValue5 = "u";
    LetterValue6 = "e";
    LetterValue7 = "l";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 6) {
    wordset = [
      "enigmas",
      "seaming",
      "ageism",
      "inseam",
      "images",
      "anime",
      "games",
      "amen"
    ]
    Letter1 = LetterA;
    Letter2 = LetterS;
    Letter3 = LetterG;
    Letter4 = LetterI;
    Letter5 = LetterE;
    Letter6 = LetterM;
    Letter7 = LetterN;
    LetterValue1 = "a";
    LetterValue2 = "s";
    LetterValue3 = "g";
    LetterValue4 = "i";
    LetterValue5 = "e";
    LetterValue6 = "m";
    LetterValue7 = "n";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 7) {
    wordset = [
      "springy",
      "spying",
      "rings",
      "spiny",
      "sprig",
      "grip",
      "spin",
      "ping"
    ]
    Letter1 = LetterP;
    Letter2 = LetterN;
    Letter3 = LetterS;
    Letter4 = LetterY;
    Letter5 = LetterR;
    Letter6 = LetterG;
    Letter7 = LetterI;
    LetterValue1 = "p";
    LetterValue2 = "n";
    LetterValue3 = "s";
    LetterValue4 = "y";
    LetterValue5 = "r";
    LetterValue6 = "g";
    LetterValue7 = "i";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 8) {
    wordset = [
      "factory",
      "crafty",
      "actor",
      "forty",
      "cart",
      "orca",
      "taco",
      "fat"
    ]
    Letter1 = LetterC;
    Letter2 = LetterA;
    Letter3 = LetterY;
    Letter4 = LetterO;
    Letter5 = LetterR;
    Letter6 = LetterT;
    Letter7 = LetterF;
    LetterValue1 = "c";
    LetterValue2 = "a";
    LetterValue3 = "y";
    LetterValue4 = "o";
    LetterValue5 = "r";
    LetterValue6 = "t";
    LetterValue7 = "f";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  if (level === 9) {
    wordset = [
      "deposit",
      "topside",
      "poised",
      "spited",
      "edits",
      "tepid",
      "diet",
      "toes"
    ]
    Letter1 = LetterO;
    Letter2 = LetterP;
    Letter3 = LetterD;
    Letter4 = LetterS;
    Letter5 = LetterE;
    Letter6 = LetterI;
    Letter7 = LetterT;
    LetterValue1 = "o";
    LetterValue2 = "p";
    LetterValue3 = "d";
    LetterValue4 = "s";
    LetterValue5 = "e";
    LetterValue6 = "i";
    LetterValue7 = "t";
    updatelettervalues();
    updatelegend();
    set7letters();
  };
  placecursor();
};

checkandloadlevel();
